<!doctype html>
<html lang="{{ config('app.locale') }}">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, max-scale=1, min-scale=1,user-scalable=no">
	<meta name="_token" content="{{ csrf_token() }}"/>
	
	
	<!--引入微信js-SDK-->
	<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script type="text/javascript" src=" {{env('CDN_RESOURCE')}}/js/mobile/wx_config.js?v={{config('app.version')}}"></script>
	
	
	<link href="{{env('CDN_RESOURCE')}}/css/mobile/campaign/christmas/mobile.css?v={{config('app.version')}}" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="https://res.wx.qq.com/open/libs/weuijs/1.1.2/weui.min.js"></script>
	<link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css">
	
	{{--<script src="http://qzonestyle.gtimg.cn/open/qcloud/video/h5/h5connect.js"></script>--}}
	
	
	<script type="text/javascript" src="https://static-app.97kid.com/wx/js/zepto.min.js"></script>
	<script type="text/javascript" src="{{env('CDN_RESOURCE')}}/js/mobile/Zepto_fx_methods.js"></script>
	<script type="text/javascript" src="{{env('CDN_RESOURCE')}}/js/mobile/login.js?v={{config('app.version')}}"></script>
	<script type="text/javascript" src="{{env('CDN_RESOURCE')}}/js/AV.analytics.js"></script>
	
	<!-- 引入腾讯云播放器 -->
	<script src="//imgcache.qq.com/open/qcloud/video/vcplayer/TcPlayer-2.2.1.js" charset="utf-8"></script>
	
	<title>Qkids久趣英语</title>

</head>
<body>

<div class="s-header">
	<div class="logo"></div>
	<div class="apply-btn-s white-btn apply" id="top-btn" data-field="{{$campaignProduct['p_id']}}">立即开团</div>
</div>


<div class="christmas-bg">
	<img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/christmas_bg.png">
</div>

<div class="wrapper">
	
	<div class="section" style="padding-top:0;">
		<div class="hot-offer">
			<span><span class="special">圣诞课</span>专用课时</span>
			<img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/group_buy_detail.png">
		</div>
		
		{{--<div class="due-date">--}}
		{{--课时有效期截止至2017年12月31日--}}
		{{--</div>--}}
		
		<div class="notice">
			成团时间：
			<span class="day">02</span>天
			<span class="hour">00</span>:
			<span class="min">00</span>:
			<span class="sec">00</span>
		</div>
		
		{{--<div id="applyGroup" class="reg-btn apply-btn" data-field="{{$campaignProduct['p_id']}}">--}}
			{{--立即开团--}}
		{{--</div>--}}
		
		

		
		<div class="fixed-btns">
			
			<div class="stick-buyAlone-btn" data-field="{{$extraCampaignProduct['p_id']}}"> ¥19.9 单独购</div>
			<div id="applyGroupFix" class="stick-group-btn" data-field="{{$campaignProduct['p_id']}}">
				立即开团
			</div>
		</div>
		
	</div>
	
	<div id="groupBuyDetail">
		<div class="group-buy-list" id="groupBuyList">
			
			<div class="captain">
				<div class="christmas-hat-icon"></div>
				<img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/empty.png">
				<span>团长</span>
			</div>
			
			<img class="group-line" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/lines.png">
			
			<div class="group-member">
				
				<div class="antler-icon"></div>
				<img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/empty.png">
				<span>驯鹿 A</span>
			</div>
			<div class="group-member">
				
				<div class="antler-icon"></div>
				<img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/empty.png">
				<span>驯鹿 B</span>
			</div>
			<div class="group-member">
				
				<div class="antler-icon"></div>
				<img src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/empty.png">
				<span>驯鹿 C</span>
			</div>
		
		</div>
		
		<div class="group-buy-status" id="groupBuyStatus">
		</div>
	</div>
	
	
	<div class="section" style="padding:10px 0 40px 0;">
		<div class="header">
			活动进度
			<div class="title-background"></div>
		</div>
		<div class="camp-step">
			<div class="item">
				<div class="group-buy-step1 icon"></div>
				<span>开团当团长</span>
			</div>
			<div class="item">
				<div class="group-buy-step2 icon"></div>
				<span>参团支付</span>
			</div>
			<div class="item">
				<div class="group-buy-step3 icon"></div>
				<span>邀请好友参团</span>
			</div>
			<div class="item">
				<div class="group-buy-step4 icon"></div>
				<span>团购完成</span>
			</div>
			<div>
				<div class="connect-line"></div>
				<div class="connect-line"></div>
				<div class="connect-line"></div>
			</div>
		</div>
	</div>
	
	
	<div class="section ">
		<div class="header">
			活动介绍
			<div class="title-background"></div>
		</div>
		<div class="story-line">
			<img class="story-img" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/p1.png">
			<div class="video-list">
				<img class="story-img" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/p2.png">
				<div class="play-icon-1 play-icon"></div>
				<div class="play-icon-2 play-icon"></div>
				<div class="play-icon-3 play-icon"></div>
				<div class="play-icon-4 play-icon"></div>
			</div>
			<img class="story-img" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/p3.png">
			<img class="story-img" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/p4.png">
			<img class="story-img" src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/p5.png">
		</div>
	</div>
	<div class="section">
		<div class="header">
			活动信息
			<div class="title-background"></div>
		</div>
		<div class="instruction">
			<div>
				<div class="num">1</div>
				<div class="text">新老用户均可开团、参团，每人仅限购买一次。</div>
			</div>
			<div>
				<div class="num">2</div>
				<div class="text">圣诞主题课为4人班，有三种难度可选，家长自主选择约课。</div>
			</div>
			{{--<div>--}}
				{{--<div class="num">3</div>--}}
				{{--<div class="text">12月16日周六开放预约，可从公众号约课入口进入。</div>--}}
			{{--</div>--}}
			<div>
				<div class="num">3</div>
				<div class="text">课时可于12月18日-12月31日期间使用，过期未使用可于1月5日之前办理退费。</div>
			</div>
			<div>
				<div class="num">4</div>
				<div class="text">新用户购买后请务必微信关注“久趣英语服务号” ，通过服务号约课、获得上课指导。</div>
			</div>
			
			{{--<div class="important">--}}
				{{--<div class="sign">*</div>--}}
				{{--<div class="text">圣诞课适用于新版客户端，G4学员及未下载新版客户端的学员请于上课前下载新版客户端。</div>--}}
			{{--</div>--}}
			{{----}}
			
		</div>
	</div>
	
	
	<div class="footer-divider"></div>
	
	<div class="footer">
		
		<div class="icon-links">
			<div class="logo-blue"></div>
		</div>

		<div class="copy-right">
			<span>Copyright @2017-2018 Qkids All Rights Reserved</span>
			<span>闽ICP备12021838号-3</span>
		</div>
	
	</div>
	
	<div class="video-mask" id="videoMask">
		<div class="close-icon icon" id="closeVideo"></div>
		<div id="videoContainer" class="video">
		</div>
	</div>
	
	<div class="buy-restrict">
		<div class="info">
			您已经购买过 ¥100／4课时，建议您购买长期课时
		</div>
		
		<a href="/wx/vip">
			<div class="small-btn confirm-btn">前往购买</div>
		</a>
	
	</div>
	
	
	<div class="group-status" id="groupStatus">
		<div class="explanation">
			
			<div class="top-banner">
				<img class="santa sad-santa"
						 src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/sad_santa.png">
				<img class="santa happy-santa"
						 src="{{env('CDN_RESOURCE')}}/img/mobile/campaign/christmas/happy_santa.png">
			
			</div>
			
			<div class="group-detail">
				<div class="title"></div>
				<div class="text"></div>
			</div>
			
			{{--<div class="detail group-full">--}}
			{{--<div class="title">已满员，请重新开团</div>--}}
			{{--<div class="text">亲爱的家长，该团已满员，请您重新开团参加双十一团购活动吧。</div>--}}
			{{--</div>--}}
			
			{{--<div class="detail group-overdue">--}}
			{{--<div class="title">活动已结束</div>--}}
			{{--<div class="text">亲爱的家长，您未在规定时间成团，系统将在3个工作日为您自动退款，请注意查收。如有需要请查看其他优惠购买课时。</div>--}}
			{{--</div>--}}
			
			{{--<div class="detail doubleEleven-group-done">--}}
			{{--<div class="title">活动已结束</div>--}}
			{{--<div class="text">亲爱的家长，活动已结束，如有需要请查看其他优惠购买课时。</div>--}}
			{{--</div>--}}
			
			{{--<div class="detail group-overdue-active">--}}
			{{--<div class="title">很遗憾</div>--}}
			{{--<div class="text">亲爱的家长，您未在规定时间成团，系统将在3个工作日为您自动退款，请注意查收。活动还未结束，重新开团参加双十一活动吧。</div>--}}
			{{--</div>--}}
			
			{{--<div class="detail group-done">--}}
			{{--<div class="title">请重新开团</div>--}}
			{{--<div class="text">亲爱的家长，该团已结束，请您重新开团参加双十一团购活动吧。</div>--}}
			{{--</div>--}}
			
			
			<div class="reg-btn ok-btn" id="okBtn">确定</div>
		</div>
	</div>
	
	<div class="buy-restrict">
		<div class="info">
			您已经购买过 ¥100／4课时，建议您购买长期课时
		</div>
		
		<a href="/wx/vip">
			<div class="small-btn confirm-btn">前往购买</div>
		</a>
	
	</div>
	
	
	<div class="share-mask">
		<div class="share-arrow"></div>
	</div>
	
	<div id="alertBox" class="alert-box"></div>

</div>

@include('template.ga')
</body>
</html>


<script type="text/javascript">
	
	(function ($) {
		
		$(function () {
			
			var currentLevel = 1;
			var previousLevel = 1;
			var offset = 5;
			var isInWechat = false;
			var userAgent = navigator.userAgent;
			//var userAgent = "Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS X) AppleWebKit/534.46(KHTML,like Geocko) Mobile/9B206 MicroMessenger/5.0";
			var wechatInfo = userAgent.match(/MicroMessenger\/([\d\.]+)/i);
			if (wechatInfo) {
				isInWechat = true;
			}
			
			// 最简的示例代码，请换成自己的 appId 和 appKey
			var appId = 'antYy9lOFi5mkU9QKjtYmRLM-gzGzoHsz';
			var appKey = 'jqyWxLyobpsmdwsJddJlDheb';
			
			// 实例化统计分析功能（注意：实例化后，SDK 会自动开始统计 PV、UV、停留页面时长等信息）
			var analytics = AV.analytics({
				// 设置 AppId
				appId: appId,
				// 设置 AppKey
				appKey: appKey,
				// 你当前应用的渠道或者你想指定的渠道（自定义）
				channel: wechatInfo ? 'weixin' : ''
			});
			
			
//			var timeout;
//			$(document).bind("scroll", function () {
//
//				clearTimeout(timeout);
//				timeout = setTimeout(function () {

//					$('.story-img').each(function(){
//						if( ($(this).offset().top -  $(window).scrollTop()) < ($(window).height() - 100 ) && ($(this).offset().top -  $(window).scrollTop()) >0 ) {
//							smoothScroll($(window),  $(this).offset().top, 300);
//						}
//					});
					
//					if ($(window).scrollTop() > $('#applyGroup').offset().top + 50) {
//						if ($('#applyGroupFix').css('display') === 'none') {
//							$('#applyGroupFix').fadeIn();
//						}
//					} else {
//						if ($('#applyGroupFix').css('display') !== 'none') {
//							$('#applyGroupFix').fadeOut();
//						}
//					}
//
//				}, 100);
//			});

//			function smoothScroll(el, to, duration) {
//				if (duration < 0) {
//					return;
//				}
//				var difference = to - $(window).scrollTop();
//				var perTick = difference / duration * 15;
//				this.scrollToTimerCache = setTimeout(function() {
//					if (!isNaN(parseInt(perTick, 10))) {
//						window.scrollTo(0, $(window).scrollTop() + perTick);
//						smoothScroll(el, to, duration - 10);
//					}
//				}.bind(this), 10);
//			}
			
			
			
			//初始化视频
			var option = {
				"m3u8": "", //请替换成实际可用的播放地址
				"autoplay" : true,      //iOS下safari浏览器，以及大部分移动端浏览器是不开放视频自动播放这个能力的
				"coverpic" : "",
				"width" :  '640',//视频的显示宽度，请尽量使用视频分辨率宽度
				"height" : '480',//视频的显示高度，请尽量使用视频分辨率高度
				"live": false,
				"systemFullscreen" : true,
			};
			
			var player;
			
			//观看视频
			$('.play-icon-1, .play-icon-2, .play-icon-3,.play-icon-4').click(function () {
				if($(this).hasClass('play-icon-1')) {
					option.m3u8 = "http://1251352844.vod2.myqcloud.com/45f5686avodtransgzp1251352844/b292a5d24564972818618453363/v.f20.mp4";
				} else if($(this).hasClass('play-icon-2')) {
					option.m3u8 = "http://1251352844.vod2.myqcloud.com/45f5686avodtransgzp1251352844/b052f53a4564972818618369860/v.f20.mp4";
				} else if($(this).hasClass('play-icon-3')) {
					option.m3u8 = "http://1251352844.vod2.myqcloud.com/45f5686avodtransgzp1251352844/b0526d654564972818618368989/v.f20.mp4";
				} else if($(this).hasClass('play-icon-4')) {
					option.m3u8 = "http://1251352844.vod2.myqcloud.com/45f5686avodtransgzp1251352844/718ccb5c4564972818617997415/v.f20.mp4";
				}
				$('#videoContainer').empty();
				player = new TcPlayer('videoContainer',option);
				player.play();
				$('#videoMask').fadeIn(300);
			});
			
			//关闭视频
			$('#closeVideo').click(function () {
				player.pause();
				$('#videoMask').fadeOut(300);
			});
			
			
			// 微信活动逻辑
			{
				var configOption = {
					timestamp: '{{$signature['timestamp']}}',
					nonceStr: '{{$signature['nonceStr']}}',
					signature: '{{$signature['signature']}}',
					jsApiList: ['onMenuShareTimeline', 'chooseWXPay', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone']
				};
				var wxconfig = new WxConfig(configOption, 'christmas');
				var account = new Account();
				var groupBuyStatus = 0;
				var campaignEnd = 1514217599;
				var creator = 0;
				var gid = '';
				
				function getGId() {
					var gid = '{{$gid}}';
					if (!gid) {
						var path = localStorage.getItem('QKidsPathname');
						
						function getMatched(name, string) {
							if (string) {
								var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
								var len = string.indexOf('?') == 0 ? 1 : 0;
								var r = string.substr(len).match(reg);
								if (r != null) return unescape(r[2]);
							}
							return null;
						}
						
						var localGid = getMatched('gid', decodeURIComponent(path));
						if (localGid) gid = localGid;
					}
					return gid;
				}
				
				account.forceLogin = false;
				account.getUserInfo(function (err, userInfo) {
					gid = getGId();
					if (gid || !err) {
						getGroupBuyInfo(gid);
					}
				});
				
				
				//提交订单
				$('.buy-btn').click(function () {
					submitOrder($(this).attr('data-field'));
				})
				$('.apply-btn, .stick-group-btn , .apply-btn-s,.stick-buyAlone-btn').click(function () {
					
					if (groupBuyStatus === 3 && groupBuyStatus === 7) {
						window.location.href = '/wx';
					} else if (groupBuyStatus === 2 || groupBuyStatus === 1) {
						$('.share-mask').fadeIn();
					} else {
						submitOrder($(this).attr('data-field'));
					}
				});
				
				//关闭提示窗口
				$('#okBtn').click(function () {
					$('#groupStatus').fadeOut();
				})
				
				//关闭分享提示
				$('.share-mask').click(function () {
					$(this).fadeOut();
				})
				
				function submitOrder(pId) {
					var campUrl = window.location.protocol + '//' + window.location.host + '/wx/christmas';
					var campPara = {
						gid: getGId(),
					};
					account.forceLogin = true;
					//提交订单久趣后台
					account.getUserInfo(function (userInfoError, userInforesult) {
						
						if (userInfoError) {
							$.toastAlert(userInfoError.message);
						} else {
							if (isInWechat) {
								//配置微信分享接口
								wxconfig.activeShare(userInforesult.shareFlag, campPara);
							}
							account.ajax({
								type: 'POST',
								path: '/s/bills',
								data: {
									productId: pId,
									payChannel: isInWechat ? 'weixin' : 'alipay',
									returnUrl: window.location.protocol + '//' + window.location.host + '/wx/verifypayment/' + pId,
									tradeType: 'JSAPI',
									openId: window.localStorage.getItem(account.openId),
									groupBuyingId: groupBuyStatus === 5 ? '' : encodeURIComponent(decodeURIComponent(campPara['gid']))
								},
								success: function (data) {
									//唤起微信支付
									if (data.status !== 'error') {
										analytics.send({
											// 事件名称
											event: 'christmas-bill-success',
											// 事件属性，任意数据
											attr: {
												productId: pId,
												billId: data.bill_id,
												isInWechat: isInWechat
											}
										});
										if (isInWechat) {
											var jsApiParameters = JSON.parse(data.jsApiParameters);
											jsApiParameters.success = function () {
												analytics.send({
													// 事件名称
													event: 'christmas-pay-success',
													// 事件属性，任意数据
													attr: {
														productId: pId,
														billId: data.bill_id,
														isInWechat: isInWechat
													}
												});
											};
											jsApiParameters.fail = function () {
												analytics.send({
													// 事件名称
													event: 'christmas-pay-fail',
													// 事件属性，任意数据
													attr: {
														productId: pId,
														billId: data.bill_id,
														isInWechat: isInWechat
													}
												});
											}
											wxconfig.pay(data.bill_id, pId, jsApiParameters, campUrl);
											
										} else {
											window.location.href = data.url;
										}
									} else {
										analytics.send({
											// 事件名称
											event: 'christmas-bill-fail',
											// 事件属性，任意数据
											attr: {
												productId: pId,
												billId: data.bill_id,
												isInWechat: isInWechat
											}
										});
										$.toastAlert('下单失败，请重试');
									}
								},
								error: function (err) {
									if (err.code === 'product.rejected.by.bought.products') {
										$.toastAlert('您已经参加活动');
										getGroupBuyInfo();
										
									}
									
								}
							});
							
						}
						
					});
				}
				
				{{--function getGroupByResult() {--}}
				{{--account.ajax({--}}
				{{--type: 'POST',--}}
				{{--path: '/s/groupbuy',--}}
				{{--data: {--}}
				{{--groupBuyingId: '{{$gid}}',--}}
				{{--},--}}
				{{--success: function (data) {--}}
				{{--if (data.status !== 'error') {--}}
				{{--setGroupBuyCountDown(data.endAt);--}}
				{{--getGroupBuyerList(data.buyers);--}}
				
				{{--} else {--}}
				{{--//$.toastAlert('下单失败，请重试');--}}
				{{--}--}}
				{{--},--}}
				{{--error: function (err) {--}}
				{{--//                        $.toastAlert(err.message, 2);--}}
				{{--}--}}
				{{--});--}}
				{{--}--}}
				
				function getGroupBuyInfo(gid) {
					
					//已经登陆
					if (!gid) {
						account.ajax({
							type: 'POST',
							path: '/s/products/1004/buying',
							
							success: function (result) {
								//已经开团
								creator = result.creatorId;
								setGroupBuyStatus(result, true);
								getGroupBuyerList(result.buyers.toString());
								resetShareDetail(result.id);
								
								
							},
							error: function (err) {
								setGroupBuyStatus(err, false);
							}
						})
					} else {
						account.ajax({
							auth: false,
							type: 'POST',
							path: '/s/products/1004/buying',
							data: {groupBuyingId: encodeURIComponent(gid)},//'fsxz2CTal9g%3D'},
							success: function (result) {
								//已经开团
								creator = result.creatorId;
								setGroupBuyStatus(result, true);
								getGroupBuyerList(result.buyers.toString());
								resetShareDetail(result.id);
							},
							error: function (err) {
								setGroupBuyStatus(err, false);
							}
						})
					}
				}
				
				
				function getGroupBuyerList(buyers) {
					account.ajax({
						auth: false,
						type: 'GET',
						path: '/s/students/socials',
						data: {ids: buyers},
						success: function (result) {
							showGroupBuyerList(result);
						},
						error: function (err) {
							$.toastAlert(err.message, 2);
						}
					});
				}
				
				function showGroupBuyerList(wechatInfoList) {
					
					
					var referralListHtml = '';
					var sortedList = [];
					
					
					if (creator !== 0) {
						var captain;
						var currentBuyer;
						var currentBuyerId = 0;
						if (JSON.parse(window.localStorage.getItem(account.userInfoKey)) !== null) {
							currentBuyerId = JSON.parse(window.localStorage.getItem(account.userInfoKey)).id;
						}
						
						
						for (var k = 0; k < wechatInfoList.length; k++) {
							if ((wechatInfoList[k].id) === creator) {
								captain = wechatInfoList[k];
							} else if (wechatInfoList[k].id === currentBuyerId) {
								currentBuyer = wechatInfoList[k];
							} else {
								sortedList.push(wechatInfoList[k]);
							}
						}
						
						if (currentBuyerId !== creator && currentBuyer) {
							sortedList.unshift(currentBuyer);
						}
						
						if (captain) {
							sortedList.unshift(captain);
						}
					}
					
					
					var buyers = [' ', 'A', 'B', 'C'];
					
					for (var i = 0; i < Math.min(4, sortedList.length); i++) {
						
						if (i === 0) {
							referralListHtml += '<div class="captain">' +
								'<div class="christmas-hat-icon"></div>' +
								'<img src="' + getAvatar(sortedList[i].avatar) + '">' +
								'<span>' + sortedList[i].nickname + '</span>' +
								'</div>' +
								'<img class="group-line" src="' + '{{env('CDN_RESOURCE')}}' + '/img/mobile/campaign/christmas/lines.png" />';
						} else {
							
							referralListHtml += '<div class="group-member">' +
								
								'<div class="antler-icon"></div>' +
								'<img src="' + getAvatar(sortedList[i].avatar) + '">' +
								'<span>' + sortedList[i].nickname + '</span>' +
								'</div>';
						}
						
					}
					
					for (var j = 0; j < ( 4 - sortedList.length); j++) {
						referralListHtml += '<div class="group-member">' +
							'<div class="antler-icon"></div>' +
							'<img src="' + '{{env('CDN_RESOURCE')}}' + '/img/mobile/campaign/christmas/empty.png" />' +
							'<span>驯鹿 ' + buyers[sortedList.length + j] + '</span>' +
							'</div>';
					}
					
					$('#groupBuyList').empty().append(referralListHtml);
					
				}
				
				function getAvatar(avatar) {
					if (!avatar) {
						return '{{env('CDN_RESOURCE')}}' + '/img/mobile/campaign/doubleEleven/pic_avatar_boy.png';
					}
					return avatar;
				}
				
				var starCount = null;
				
				function setGroupBuyCountDown(status, endAt) {
					if (starCount) clearInterval(starCount);
					if (status == 0) {
						starCount = setInterval(function () {
							
							var timestamp = Date.parse(new Date());
							if (timestamp >= endAt) {
								// 团购已经结束
								$('.notice').text('该团购已经到期!');
								clearInterval(starCount);
								
							} else if (timestamp < endAt) {
								var timeDiff = endAt - timestamp;
								var day = Math.floor(timeDiff / 1000 / 60 / 60 / 24);
								var hour = Math.floor(timeDiff / 1000 / 60 / 60 % 24);
								var min = Math.floor(timeDiff / 1000 / 60 % 60);
								var sec = Math.floor(timeDiff / 1000 % 60);
								
								if (day < 10) {
									day = "0" + day;
								}
								if (hour < 10) {
									hour = "0" + hour;
								}
								if (min < 10) {
									min = "0" + min;
								}
								if (sec < 10) {
									sec = "0" + sec;
								}
								var countDownTime = hour + ":" + min + ":" + sec;
								//$('.notice').text('成团时间: ' + day + '天' + countDownTime);
								$('.notice .day').text(day);
								$('.notice .hour').text(hour);
								$('.notice .min').text(min);
								$('.notice .sec').text(sec);
							}
						}, 1000);
						
					} else if (status == 1) {
						$('.notice').text('已成团');
					} else {
						$('.notice').text('已过期');
					}
					
				}
				
				//已登陆
				
				//setGroupBuyStatus({}, true);
				function setGroupBuyStatus(gpDetail, status) {
					
					//if (!gpDetail || !gpDetail.id) return;
					
					//  status: 1->已报名 2->未报名

//                alert(groupBuyTimeStatus(gpDetail.endAt) + '-'  + campaignTimeStatus());
					
					var currentBuyerId = 0;
					if (JSON.parse(window.localStorage.getItem(account.userInfoKey)) !== null) {
						currentBuyerId = JSON.parse(window.localStorage.getItem(account.userInfoKey)).id;
					}
					
					var inGroup = gpDetail.buyers && gpDetail.buyers.indexOf(currentBuyerId) >= 0;
					
					var cStatus = campaignTimeStatus();
					
					var endAt1 = new Date().getTime() / 1000 + 1000;
					var endAt2 = new Date().getTime() / 1000 - 1000;
					
					//status = true;
					//cStatus = true;
					//inGroup = true;
					
					// 组团中
					//gpDetail = { id: 1, status: 2, buyerCount: 2, endAt: endAt1, buyers: [9]};
					// 团成功
					//gpDetail = { id: 1, status: 1, buyerCount: 4, endAt: endAt2, buyers: [7,8,9,27]};
					// 团过期
					//gpDetail = { id: 1, status: 2, buyerCount: 4, endAt: endAt2, buyers: [9]};
					
					setGroupBuyCountDown(gpDetail.status, gpDetail.endAt * 1000);
					if (gpDetail.status === 0) {
						if (inGroup) displayGroupBuyStatus(2, gpDetail.buyerCount);
						else displayGroupBuyStatus(8, gpDetail.buyerCount);
					} else if (gpDetail.status === 1) {
						if (inGroup) displayGroupBuyStatus(1);
						else {
							if (cStatus) displayGroupBuyStatus(5);
							else displayGroupBuyStatus(7);
						}
					} else {
						if (cStatus) {
							if (inGroup) displayGroupBuyStatus(4);
							else displayGroupBuyStatus(6)
						} else {
							if (inGroup) displayGroupBuyStatus(3);
							else displayGroupBuyStatus(7);
						}
					}
					
				}
				
				function groupBuyTimeStatus(groupBuyEnd) {
					return (new Date).getTime() / 1000 <= groupBuyEnd;
				}
				
				function campaignTimeStatus() {
					return (new Date).getTime() / 1000 <= campaignEnd;
				}
				
				function displayGroupBuyStatus(status, buyerCounter) {
					$('.camp-step .icon').removeClass('active');
					if (status === 1) {
						$('.group-buy-step4').addClass('active');
						//happy monkey
						// 团购成功( 已报名 已成团 活动时间未到期 )
						//亲爱的家长，您已成功购入圣诞活动课时（￥9.9/1 课时），北美外教给您准备了有趣的课程，快去预约上课吧！
						$('.apply-btn, .stick-group-btn').css('width','100%').text('团购成功，分享给好友');
						$('.stick-buyAlone-btn').hide();
						
						$('.group-buy-status').text('当前团购成功');
						$('.happy-santa').show().siblings('.santa').hide();
						$('.group-detail .title').text('团购成功');
						$('.group-detail .text').text('亲爱的家长，您已成功购入圣诞活动课时（￥9.9/1课时），北美外教给您准备了有趣的课程，快去预约上课吧！');
						$('#top-btn').text('立即分享');
						$('#groupStatus').show();
						groupBuyStatus = 1;
						
					} else if (status === 2) {
						//尚未成团 (已报名 团没有满 团购时间未到期 活动时间还没到期  )
						$('.apply-btn , .stick-group-btn').css('width','100%').text('邀请好友参团');
						$('.stick-buyAlone-btn').hide();
						
						$('.group-buy-status').text(' 还差' + (4 - buyerCounter) + '人即可成团，邀请更多好友共享');
						$('#top-btn').text('立即邀请');
						groupBuyStatus = 2;
						$('.group-buy-step3').addClass('active');
						
					} else if (status === 3) {
						//normal monkey
						//活动已结束( 已报名 团没有满 团购时间到期 活动时间已到期)
						//亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3个工作日为您自动退款，请注意查收。如有需要请查看其他优惠购买课时。
						$('.apply-btn, .stick-group-btn').text('查看其他优惠').hide();
						$('.stick-buyAlone-btn').css('width','100%');
						
						$('.group-buy-status').text('圣诞活动已结束');
						$('.sad-santa').show().siblings('.santa').hide();
						$('.group-detail .title').text('活动已结束');
						$('.group-detail .text').text('亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3-5个工作日为您自动退款，请注意查收。如有需要请查看其他优惠购买课时。');
						$('#top-btn').hide();
						$('#groupStatus').show();
						groupBuyStatus = 3;
						
					} else if (status === 4) {
						$('.group-buy-step1').addClass('active');
						//sad monkey
						//很遗憾( 已报名 团没有满 团购时间到期 活动时间未到期)
						//亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3个工作日为您自动退款，请注意查收。活动还未结束，重新开团参加圣诞活动吧。
						$('.apply-btn, .stick-group-btn').text('重新开团');
						$('.group-buy-status').text('未能组团成功，请重新开团');
						$('.sad-santa').show().siblings('.santa').hide();
						$('.group-detail .title').text('很遗憾');
						$('.group-detail .text').text('亲爱的家长，您所在的团未在规定时间内组团成功，系统将在3-5个工作日为您自动退款，请注意查收。活动还未结束，重新开团参加圣诞活动吧。');
						$('#top-btn').text('重新开团');
						$('#groupStatus').show();
						groupBuyStatus = 4;
						
					} else if (status === 5) {
						$('.group-buy-step4').addClass('active');
						//normal monkey
						// 该团已满，重新开团( 未报名 团已满 活动时间未到期 )
						//亲爱的家长，该团已满员，请您重新开团参加圣诞团购活动吧。
						$('.apply-btn, .stick-group-btn').text('重新开团');
						$('.group-buy-status').text('该团已满员，请重新开团');
						$('.sad-santa').show().siblings('.santa').hide();
						$('.group-detail .title').text('该团已满，重新开团');
						$('.group-detail .text').text('亲爱的家长，该团已满员，请您重新开团参加圣诞团购活动吧。');
						$('#groupStatus').show();
						$('#top-btn').text('重新开团');
						groupBuyStatus = 5;
						
					} else if (status === 6) {
						//sad monkey
						//请重新开团(  未报名 团没有满 团购时间已经到期 活动时间未到期)
						//亲爱的家长，该团已结束，请您重新开团参加圣诞团购活动吧。
						$('.apply-btn, .stick-group-btn').text('重新开团');
						$('.group-buy-status').text('该团团购时间结束，请重新开团');
						$('.sad-santa').show().siblings('.santa').hide();
						$('.group-detail .title').text('请重新开团');
						$('.group-detail .text').text('亲爱的家长，该团团购时间结束，请您重新开团参加圣诞团购活动吧。');
						$('#groupStatus').show();
						$('#top-btn').text('重新开团');
						groupBuyStatus = 6;
						$('.group-buy-step1').addClass('active');
						
					} else if (status === 7) {
						//normal monkey
						//活动已结束( 未报名 活动时间到期 )
						//亲爱的家长，活动已结束，如有需要请查看其他优惠购买课时。
						$('.apply-btn, .stick-group-btn').text('查看其他优惠').hide();
						$('.stick-buyAlone-btn').css('width','100%');
						
						$('.group-buy-status').text('活动已经结束');
						$('.normal-santa').show().siblings('.santa').hide();
						$('.group-detail .title').text('活动已结束');
						$('.group-detail .text').text('亲爱的家长，活动已结束，如有需要请查看其他优惠购买课时。');
						$('#groupStatus').show();
						$('#top-btn').hide();
						groupBuyStatus = 7;
					} else if (status === 8) {
						//参加活动( 未报名 团购活动没有满 活动时间未到期 )
						$('.apply-btn, .stick-group-btn').text('立即参团');
						$('.group-buy-status').text(' 还差' + (4 - buyerCounter) + '人即可成团，邀请更多好友共享');
						$('#top-btn').text('立即参团');
						groupBuyStatus = 8;
						$('.group-buy-step2').addClass('active');
					} else if (status === 9) {
						//参加活动( 未报名 团购活动没有满 团购时间到期 活动时间未到期 )
						$('.apply-btn, .stick-group-btn').text('重新开团');
						$('.group-buy-status').text('该团已结束，请重新开团');
						$('#top-btn').text('重新开团');
						groupBuyStatus = 9;
					}
				}
				
				function resetShareDetail(gid) {
					var campPara = [];
					campPara['gid'] = gid;
					account.getUserInfo(function (err, result) {
						if (!err && isInWechat) {
							//配置微信分享接口
							wxconfig.activeShare(result.shareFlag, campPara);
						}
					});
					
				}
				
			}
		})
		
	})(window.Zepto);


</script>

